cls.__doc__ = 'Constructs a %s, taking sequential arguments in the order they were\nspecified by the format description (or named keyword arguments!):\n\n%s' % (classname, fmts)
def checkinvars(cls, o):
for invar in cls._invars:
if not invar(o):
fc = invar.func_code
raise AssertionError('Invariant failed after unpacking:\n%s' % debugline(fc))
continue
def unpack(cls, data):
sz = cls._struct.size
o = cls(*cls._struct.unpack(data[:sz]))
try:
checkinvars(cls, o)
except AssertionError:
log.error('wrong data: %s', to_hex(data))
raise
return (o, data[sz:])
unpack = (classmethod,)(unpack)
def pack(self):
checkinvars(self.__class__, self)
attrs = [ getattr(self, field) for field in self.__slots__ ]
return self._struct.pack(*attrs)
def __eq__(self, other):
for attr in self.__slots__:
if getattr(other, attr, sentinel) != getattr(self, attr):